package com.flyduck.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: flyduck-admin
 * @description:
 * @author: flyduck
 * @create: 2020-05-11 11:12
 **/
public class DateUtil {
    public static final SimpleDateFormat yyyy_MM_dd = new SimpleDateFormat("yyyy-MM-dd");
    public static final SimpleDateFormat yyyy_MM_dd_HH_mm_ss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     *
     * @param date 日期
     * @param sdf 格式
     * @return date按sdf格式后的字符串
     * @throws NullPointerException sdf为null
     */
    public static String dateToStr(Date date,SimpleDateFormat sdf){
        return date == null ? "" : sdf.format(date);
    }


    public static Date strToDate(String date,SimpleDateFormat sdf){
        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }finally {
            return null;
        }
    }
}
